package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

public class Power extends AbstractMapleStoryObject {
    public static Image[] images = new Image[10];

    static {
        for (int i = 0; i < 10; i++) {
            images[i] = ImageUtil.getImage("power" + i);
        }
    }

    public int value;

    public Power(MapleStoryClient msc, int x, int y) {
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.value = msc.hero.hitValue;
        this.width = images[0].getWidth(null);
        this.height = images[0].getHeight(null);
    }

    public Power() {
        this.speed = 5;
        this.live = true;
    }

    @Override
    public void draw(Graphics g) {
        if (!live) {
            msc.powers.remove(this);
            return;
        }
//        Font font = g.getFont();
//        g.setFont(new Font("微软雅黑", Font.BOLD, 25));
//        g.drawString(value + "", x, y);
//        g.setFont(font);
        drawValue(g);
        move();
    }

    public void drawValue(Graphics g) {
        int power = this.value;//1728
        if (power >= 9999) {
            power = 9999;
        }
        int units = power % 10;//8
        power = power / 10;//172
        int tens = power % 10;//2
        power = power / 10;//17
        int hundreds = power % 10;//7
        power = power / 10;//1

        int thousands = power;
        if (tens == 0 && hundreds == 0 && thousands == 0 && units != 0) {
            g.drawImage(images[units], x, y, null);
        } else if (hundreds == 0 && thousands == 0 && tens != 0) {
            g.drawImage(images[tens], x, y, null);
            g.drawImage(images[units], x + this.width, y - this.height / 2, null);
        } else if (thousands == 0 && hundreds != 0) {
            g.drawImage(images[hundreds], x, y, null);
            g.drawImage(images[tens], x + this.width, y - this.height / 2, null);
            g.drawImage(images[units], x + this.width * 2, y, null);
        } else if (thousands != 0) {
            g.drawImage(images[thousands], x, y, null);
            g.drawImage(images[hundreds], x + this.width, y - this.height / 2, null);
            g.drawImage(images[tens], x + this.width * 2, y, null);
            g.drawImage(images[units], x + this.width * 3, y - this.height / 2, null);
        }
    }

    @Override
    public void move() {
        if (this.y <= 300) {
            this.live = false;
        }
        this.y -= speed;
    }

}
